<?php

namespace App\Transformers\Frontend;

use App\Models\Advertisement;
use League\Fractal\TransformerAbstract;

class AdvertisementTransformer extends TransformerAbstract
{

    protected $availableIncludes = ['bannering'];

    protected $hidden = ['deleted_at'];

    public function transform(Advertisement $model)
    {
        $model->makeHidden($this->hidden);
        return $model->attributesToArray();
    }

    public function includeBannering(Advertisement $model)
    {
        $banner = $model->bannering;
        if (!$banner) {
            return $this->null();
        }
        return $this->item($banner, new FileTransformer());
    }
}